package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BmsLeaveApproval;
import com.macro.mall.query.BmsLeaveApprovalQuery;
import com.macro.mall.service.BmsLeaveApprovalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "BmsLeaveApprovalController")
@Tag(name = "BmsLeaveApprovalController", description = "请假")
@RequestMapping("/leaveApproval")
public class BmsLeaveApprovalController {

    @Resource
    private BmsLeaveApprovalService leaveApprovalService;

    @ApiOperation("分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> list(@RequestBody BmsLeaveApprovalQuery query) {
        try {
            List<BmsLeaveApproval> list = leaveApprovalService.findList(query);
            return CommonResult.success(CommonPage.restPage(list));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("获取审批人列表")
    @RequestMapping(value = "/approvalUserList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<?> getApprovalUserList() {
        try {
            List<Map<String, String>> approvalUserList = leaveApprovalService.getApprovalUserList();
            return CommonResult.success(approvalUserList);
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("审批")
    @RequestMapping(value = "/approval", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsLeaveApprovalQuery query) {
        try {
            int i = leaveApprovalService.approval(query);
            return CommonResult.success("审批完成");
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }
}
